//
//  XMReturnDetailInfoView.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/24.
//

#import "XMReturnDetailInfoView.h"

@interface XMReturnDetailInfoView ()

@property (nonatomic, strong) UILabel *orderNoLabel;
@property (nonatomic, strong) UILabel *returnPriceLabel;
@property (nonatomic, strong) UILabel *timeCountDownLabel;

@property (nonatomic, strong) UIImageView *progressImgView;
@property (nonatomic, strong) UILabel *agreeTitleLabel;
@property (nonatomic, strong) UILabel *returnCompleteLabel;

@property (nonatomic, strong) UIButton *fucBtn;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UILabel *explainLabel;
@property (nonatomic, strong) UILabel *suppleLabel;

@property (nonatomic, strong) NSMutableArray *infoLabelArr;

@end

@implementation XMReturnDetailInfoView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.navView];
    self.navTitleLabel.text = @"退款详情";
    self.backgroundColor = kColorHEX(0xF6F6F6);
    //订单信息
    UIView *orderInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, kNavagationBarH, self.width, KScaleWidth(82.0))];
    orderInfoView.backgroundColor = kColorHEX(0xffffff);
    [self addSubview:orderInfoView];
    {
        UILabel *noTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), KScaleWidth(16.0), KScaleWidth(70.0), KScaleWidth(21.0)) font:KFontSize(15.0) textColor:kColorHEX(0x999999)];
        noTitleLabel.text = @"订单编号";
        [orderInfoView addSubview:noTitleLabel];
        UILabel *priceTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), noTitleLabel.maxY + KScaleWidth(8.0), noTitleLabel.width, KScaleWidth(21.0)) font:KFontSize(15.0) textColor:kColorHEX(0x999999)];
        priceTitleLabel.text = @"退款金额";
        [orderInfoView addSubview:priceTitleLabel];
        [orderInfoView addSubview:self.orderNoLabel];
        [orderInfoView addSubview:self.returnPriceLabel];
    }
    //进度
    UIView *progressView = [[UIView alloc] initWithFrame:CGRectMake(0, orderInfoView.maxY + KScaleWidth(8.0), self.width, KScaleWidth(100.0))];
    progressView.backgroundColor = kColorHEX(0xF6F6F6);
    [self addSubview:progressView];
    
    {
        UIImageView *progressImgView = [[UIImageView alloc] initWithFrame:CGRectMake((self.width - KScaleWidth(290.0))/2, KScaleWidth(24.0), KScaleWidth(290.0), KScaleWidth(24.0))];
        _progressImgView = progressImgView;
        [progressView addSubview:progressImgView];
        UILabel *applyTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(progressImgView.x + KScaleWidth(12.0) - KScaleWidth(80.0)/2, progressImgView.maxY + KScaleWidth(8.0), KScaleWidth(80.0), KScaleWidth(21.0)) font:KFontSize(15.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentCenter];
        applyTitleLabel.text = @"发起申请";
        [progressView addSubview:applyTitleLabel];
        UILabel *agreeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.width/2 - KScaleWidth(120.0)/2, applyTitleLabel.y, KScaleWidth(120.0), applyTitleLabel.height) font:KFontSize(15.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentCenter];
        _agreeTitleLabel = agreeTitleLabel;
        agreeTitleLabel.text = @"对方同意退款";
        [progressView addSubview:agreeTitleLabel];
        
        UILabel *returnCompleteLabel = [[UILabel alloc] initWithFrame:CGRectMake(progressImgView.maxX - KScaleWidth(12.0) - KScaleWidth(80.0)/2, agreeTitleLabel.y, KScaleWidth(80.0), agreeTitleLabel.height) font:KFontSize(15.0) textColor:kColorHEX(0x999999) textAlignment:NSTextAlignmentCenter];
        _returnCompleteLabel = returnCompleteLabel;
        returnCompleteLabel.text = @"退款完成";
        [progressView addSubview:returnCompleteLabel];
    }
    //退款信息
    UIView *orderStatusView = [[UIView alloc] initWithFrame:CGRectMake(0, progressView.maxY + KScaleWidth(8.0), self.width, KScaleWidth(255.0))];
    orderStatusView.backgroundColor = kColorHEX(0xffffff);
    [self addSubview:orderStatusView];
    {
        [orderStatusView addSubview:self.statusLabel];
        [orderStatusView addSubview:self.explainLabel];
        [orderStatusView addSubview:self.suppleLabel];
        [orderStatusView addSubview:self.fucBtn];
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, KScaleWidth(96.0), self.width, 1)];
        lineView.backgroundColor = kColorHEX(0xF1F1F1);
        [orderStatusView addSubview:lineView];
        NSArray *titleArr = @[@"返回账户", @"退款原因", @"发起时间", @"退款描述"];
        for (int i = 0; i < 4; i ++) {
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), lineView.maxY + KScaleWidth(9.0) + (KScaleWidth(21.0) + KScaleWidth(8.0))*i, KScaleWidth(80.0), KScaleWidth(21.0)) font:KFontSize(15.0) textColor:kColorHEX(0x666666)];
            titleLabel.text = titleArr[i];
            [orderStatusView addSubview:titleLabel];
            
            UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(124.0), titleLabel.y, self.width - KScaleWidth(124.0) - KScaleWidth(16.0), titleLabel.height) font:KFontSize(15.0) textColor:kColorHEX(0x333333)];
            [orderStatusView addSubview:infoLabel];
            [self.infoLabelArr addObject:infoLabel];
        }
    }
}

- (void)setContentWithReturnModel:(XMReturnInfoModel *)returnInfoModel {
    _orderNoLabel.text = @"1234567890123456";
    _returnPriceLabel.text = @"¥99.0";
    
    _statusLabel.text = @"等待对方处理";
    _explainLabel.text = @"还剩1天1时24分";
    _suppleLabel.hidden = NO;
    
    _progressImgView.image = ImageNamed(@"order_refund_status_1_img");
    
    NSArray *titleArr = @[@"微信", @"计划有变", @"2025.03.02 11:00", @"描述内容描述内容描述内容描述内容描述内容"];
    for (int i = 0; i < self.infoLabelArr.count; i ++) {
        UILabel *infoLabel = self.infoLabelArr[i];
        infoLabel.text = titleArr[i];
        if (i == 3) {
            CGFloat height = [infoLabel.text getHeightWithFont:KScaleWidth(15.0) withWidth:infoLabel.width] + KScaleWidth(10.0);
            infoLabel.height = MAX(height, KScaleWidth(21.0));
            infoLabel.superview.height = infoLabel.maxY + KScaleWidth(15.0);
        }
    }
}

- (void)fucAction:(UIButton *)button {
    
}

#pragma mark - Init
- (UILabel *)orderNoLabel {
    if (!_orderNoLabel) {
        _orderNoLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(92.0), KScaleWidth(16.0), self.width - KScaleWidth(92.0) - KScaleWidth(16.0), KScaleWidth(21.0)) font:KFontSize(15.0) textColor:kColorHEX(0x999999)];
    }
    return _orderNoLabel;
}

- (UILabel *)returnPriceLabel {
    if (!_returnPriceLabel) {
        _returnPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderNoLabel.x, _orderNoLabel.maxY + KScaleWidth(8.0), _orderNoLabel.width, _orderNoLabel.height)];
    }
    return _returnPriceLabel;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), KScaleWidth(16.0), self.width/2 - KScaleWidth(16.0), KScaleWidth(22.0)) font:KFontSize(16.0) textColor:kColorHEX(0x333333)];
    }
    return _statusLabel;
}

- (UILabel *)explainLabel {
    if (!_explainLabel) {
        _explainLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), self.statusLabel.maxY + KScaleWidth(5.0), _statusLabel.width, KScaleWidth(18.0)) font:KFontSize(13.0) textColor:kColorHEX(0xDD4B39)];
    }
    return _explainLabel;
}

- (UILabel *)suppleLabel {
    if (!_suppleLabel) {
        _suppleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), self.explainLabel.maxY + KScaleWidth(2.0), self.width - KScaleWidth(16.0)*2, KScaleWidth(18.0)) font:KFontSize(13.0) textColor:kColorHEX(0x999999)];
    }
    return _suppleLabel;
}

- (UIButton *)fucBtn {
    if (!_fucBtn) {
        _fucBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(15.0) frame:CGRectMake(self.width - KScaleWidth(16.0) - KScaleWidth(90.0), KScaleWidth(19.0), KScaleWidth(90.0), KScaleWidth(38.0)) title:@"撤销申请" titleColor:kColorHEX(0x333333)];
        [_fucBtn setGradientLayerWithLocations:@[@(0), @(1.0)] colors:@[(__bridge id)kColorHEX(0xFFD800).CGColor, (__bridge id)kColorHEX(0xFFE44E).CGColor] startPoint:CGPointMake(0.5, 0.37) endPoint:CGPointMake(0.03, 0.37)];
        [_fucBtn setCornerRadius:_fucBtn.height/2];
        [_fucBtn addTarget:self action:@selector(fucAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _fucBtn;
}

- (NSMutableArray *)infoLabelArr {
    if (!_infoLabelArr) {
        _infoLabelArr = [NSMutableArray array];
    }
    return _infoLabelArr;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
